import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import './myHealthrecords.scss'
import app from '../../main'


export default class MyHealthrecords extends Component {

    config = {
        navigationBarTitleText: '健康档案'
    }
    constructor() {
        super(...arguments)
        this.state = {
            patientInfo: []
        }
    }
    // 查看档案
    handeClick(id) {
        app.navigateTo('../patientInformation/patientInformation'+'?id='+id);
    }
    //添加病历
    gotoquicklyConsultationModify(){
        app.navigateTo('../patientInformation/patientInformation');
    }

    offset = 0;
    length = 25;
    total = 0;
    isFinlsh = false;

    //上拉加载
    onReachBottom() {
        if ((this.offset + this.length) < this.total) {
            app.toast('正在加载----')
            this.offset = this.offset + this.length;
            this.isFinlsh = false;
            //调用接口
            this.getDate()
        } else {
            app.toast('没有更多数据了咯')
            this.isFinlsh = true;
        }
    }

    // 获取患者信息
    getDate() {
        let me = this
        let data = { offset: this.offset, length: this.length,id:this.$router.params.id}
        console.log(this.$router.params.id)
        let dataArray=[]
        app.post('web/healthArchives/healthArchivesList', data, function (res) {
            dataArray = res.data.result.list
            me.total=res.data.result.total
                me.setState({
                patientInfo: dataArray
            })
        })
    }

    componentDidShow() {
        this.getDate();
    }

    render() {
        // 患者标签
        const patientInfos = this.state.patientInfo.map((item) => {
            return <View className='box' onClick={this.handeClick.bind(this,item.id)} >
                        <View className='info'>
                            <View className='text'>
                                <View>
                                    <Text className='bane'>{item.name}</Text>
                                </View>
                                <View className='ageSex'>
                                    <Text>{item.gender}  </Text><Text className='t'>{item.age}岁</Text>
                                </View>
                            </View>
                        </View>
                    </View>
        })
        return (
            <View className='bigBox'>
                {/* 患者信息 */}
                {patientInfos}
                {/* 添加患者 */}
                <View className='box'>
                    <View className='uninfo' onClick={this.gotoquicklyConsultationModify.bind(this)}>
                        <View className='text'>
                            <View>
                                <Text className='bane'>+</Text>
                            </View>
                            <View>
                                <Text className='ageSex'>添加患者</Text>
                            </View>
                        </View>
                    </View>
                </View>
            </View>
        )
    }
}